package cn.akwangl.socket.nio;

import lombok.extern.slf4j.Slf4j;

import java.io.*;

@Slf4j
public class NoBufferStreamCopy implements FileCopy {
    @Override
    public void copyFile(File source, File target) {
        CreateTestData.fileInit(target, true);

        FileInputStream fin = null;
        FileOutputStream fos = null;
        try {
            fin = new FileInputStream(source);
            fos = new FileOutputStream(target);

            int result;
            while ((result = fin.read()) != -1) {
                fos.write(result);
            }
        } catch (FileNotFoundException e) {
            log.error("找不到文件", e);
        } catch (IOException e) {
            log.error("IO 异常", e);
        } finally {
            try {
                fin.close();
                fos.close();
            } catch (IOException e) {
                log.error("释放资源失败", e);
            }
        }
    }
}
